package com.richapp.launcher.ui.fragments;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

public abstract class BaseFragment extends Fragment {
	public static final int LIGHTCONTROLFLAG = 0;
	public static final int CURTAINSCONTROLFLAG = 1;
	public static final int POWERMONITORFLAG = 2;
	public static final int CAMERACONTROLFLAG = 3;
	public static final int POWERCONTROLFLAG = 4;
	public static final int SCENARIOCONTROLFLAG = 5;
	protected abstract void init(View view);

	protected void replaceFragment(Fragment fragment,int id,OnBackStackChangedListener backListener) {
		FragmentManager fragmentManager = getFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		fragmentManager.addOnBackStackChangedListener(backListener);
		if (!fragment.isAdded()) {
            fragmentTransaction.replace(id,fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
		}else {
			fragmentTransaction.show(fragment).commit();
		}
	}
	protected void replaceFragment(Fragment fragment,int id) {
		FragmentManager fragmentManager = getFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		if (!fragment.isAdded()) {
			fragmentTransaction.replace(id,fragment);
			fragmentTransaction.commit();
		}else {
			fragmentTransaction.show(fragment).commit();
		}
	}
}
